/**
 * 2011-11-17下午7:49:15
 */
package dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import util.MysqlConn;
import bean.Userinfo;

/**
 * @author Baicai 用户信息的修改与增加
 */
public class UpdateUser {

	/**
	 * 修改用户信息
	 * 
	 * @param phone
	 * @param info
	 * @return boolean
	 */
	public static boolean update(String phone, String info, String num) {

		try {
			String string = "select user_id from user where userinfo_num ='"
					+ num + "'";
			MysqlConn.setSqlString(string);
			ResultSet resultSet;
			resultSet = MysqlConn.queryDB();
			resultSet.next();
			int id = resultSet.getInt(1);
			MysqlConn.free();
			string = "update user set user_phone='" + phone
					+ "',user_information='" + info + "' where user_id=" + id;// 连接sql语句
			MysqlConn.setSqlString(string);
			if (MysqlConn.updateDB() == 1) {
				MysqlConn.free();
				return true;
			}
			return false;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			MysqlConn.free();
		}

		return false;
	}

	/**
	 * 增加用户信息
	 * 
	 * @param phone
	 * @param info
	 * @param userinfo
	 * @return boolean
	 */
	public static boolean insert(String phone, String info, Userinfo userinfo) {
		
		try {
			String string = "insert into user values(NULL,5,'" + phone +"','"
					+ info + "','" + userinfo.getUserinfoNum()
					+ "','" + userinfo.getUserinfoName() + "','"
					+ userinfo.getUserinfoSex()+"')";
			System.out.println(string);
			MysqlConn.setSqlString(string);// 拼接字符串
			MysqlConn.updateDB();
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			MysqlConn.free();
		}

		return false;
	}
}
